package com.zjj.shiro.authroization.permission;

import java.util.HashSet;
import java.util.Set;

import org.apache.shiro.authz.Permission;

public class MyCustomPermission implements Permission {
	
	// 本次请求的资源
	private String accessResource;
	
	// 存储允许访问的资源菜单
	private Set<String> availableResources;

	public MyCustomPermission(String accessResource) {
		this.accessResource = accessResource;
	}

	public MyCustomPermission(Set<String> availableResources) {
		if (availableResources == null) {
			availableResources = new HashSet<String>();
		}
		this.availableResources = availableResources;
	}
	@Override
	public boolean implies(Permission p) {
		if (!(p instanceof MyCustomPermission)) {
			return false;
		}
		MyCustomPermission myPermission = (MyCustomPermission) p;
		String accessResource = myPermission.accessResource;
		return availableResources.contains(accessResource);
	}

}
